<?php
defined( '_VALID_MOS' ) or die( 'Restricted access' );

class HTML_news{
	function viewPromotion ( &$row, &$lsContent, &$lsNewsOthersUser, &$lsNewsOthersUserBlock ){
	global $mosConfig_live_site;	
		//path image
		$path = $mosConfig_live_site."/uploads/news";
		$pathContent = $mosConfig_live_site."/uploads/content";
		//Tinh thoi gian
		$starttime=time();
		$endtime=strtotime($row->end_date);
		 
		$timediff = $endtime-$starttime;
		$days=intval($timediff/86400);
		$remain=$timediff%86400;
		$hours=intval($remain/3600);
		$remain=$remain%3600;
		$mins=intval($remain/60);
		$secs=$remain%60;
		?>
		<div class="w_title_website">
			<div class="w_show_title_website"><?php echo $row->title;?></div>
			<div class="clearfix"></div>
			<div class="w_show_content">
				<div class="viewNews">
					<div class="timer_start_end">
						<p class="datetime">
							Bắt đầu từ ngày: <span class="red"><?php echo unFormatDate($row->start_date,"d/m/Y H:i:s");?></span> đến <span class="red"><?php echo unFormatDate($row->end_date,"d/m/Y H:i:s");?></span>
							<?php if($row->state == 1){?>
							<span class="timer">Thời gian còn lại: <?php echo $timediff=$days.' ngày, '.$hours.' giờ, '.$mins.' phút';?></span>
							<?php }else{?>
							<span class="timer" style="padding-left:140px; color:red; text-transform: uppercase;">Đã hết khuyến mãi</span>
							<?php }?>
						</p>
						<?php if ($row->state==0){?>
						<div class="timer_stop"></div>
						<?php }?>
					</div>
					<p class="intro"><?php echo $row->introtext;?></p>
					<p class="image"><img src="<?php echo $path;?>/large/<?php echo $row->largeImage;?>" alt="<?php echo $row->title;?>" border="0" /></p>
					<p><?php echo $row->fulltext;?></p>
				</div>
				<div class="clearfix"></div>
				<div class="tabbed_box" id="tabbed_box_1">
				    <div class="tabbed_area">
				        <ul class="tabs">
				            <li><a class="tab" title="content_1" href="javascript:void(0);">Sản phẩm khuyến mãi</a></li>
				            <li><a class="tab" title="content_2" href="javascript:void(0);">Khuyến mãi đang chạy</a></li>
				            <li><a class="tab active" title="content_3" href="javascript:void(0);">Khuyến mãi đã chạy</a></li>
				        </ul>
				        <div class="content" id="content_1" style="display: none;">
				        	<ul class="showProducts">
				            	<?php
								for ($i=0; $i<count($lsContent); $i++){
									$linkurl = sefRelToAbs("index.php?option=com_content&task=view&id=".$lsContent[$i]->id).$lsContent[$i]->title_alias;
									if (($i+1)%5 == 0){
										$style = ' style="margin-right:0;"';
									}else{
										$style = ' style="margin-right:13px;"';
									}
									?>
									<li>
										<div class="w_lsProduct"<?php echo $style;?>>
											<a href="<?php echo $linkurl;?>" class="screenshot" rel="<?php echo $pathContent;?>/large/<?php echo $lsContent[$i]->largeImage;?>">
												<?php if ($lsContent[$i]->muc_giam == 0){?>
												<img src="<?php echo $pathContent;?>/medium/<?php echo $lsContent[$i]->mediumImage;?>" border="0" />
												<?php }else{?>
												<img src="<?php echo $pathContent;?>/thumbnail/<?php echo $lsContent[$i]->thumbnailImage;?>" style="width:70px;" border="0" />
												<?php }?>
											</a>
											<div class="clearfix"></div>
											<a href="<?php echo $linkurl;?>" class="screenshot" rel="<?php echo $path;?>/large/<?php echo $lsContent[$i]->largeImage;?>"><?php echo $lsContent[$i]->title;?></a><br />
											<?php if ($lsContent[$i]->giam_gia == 0){?>
											<span><?php echo number_format($lsContent[$i]->price,0,".",",");?> VNĐ</span>
											<?php }else{?>
											<span style="font-size:11px;">Giá bán: <?php echo number_format($lsContent[$i]->price_giam,0,".",",");?> VNĐ</span>
											<div class="clearfix"></div>
											<span style="font-size:11px; text-decoration: line-through; color:#707070;">Giá cũ: <?php echo number_format($lsContent[$i]->price,0,".",",");?> VNĐ</span>
											<?php }?>
											<?php if ($lsContent[$i]->muc_giam > 0){?>
											<div class="muc_giam">Giảm: <?php echo number_format($lsContent[$i]->muc_giam,0,".",",");?> VNĐ</div>
											<?php }?>
										</div>
									</li>
									<?php
								} 
								?>
							</ul>
				        </div>
				        <div class="content" id="content_2" style="display: none;">
				        	<ul>
				            	<?php
								for ($i=0; $i<count($lsNewsOthersUser); $i++){
								$link = sefRelToAbs("index.php?option=com_news&task=view&id=".$lsNewsOthersUser[$i]->id).$lsNewsOthersUser[$i]->title_alias;	
								if (($i+1%2) == 0)	$styleBorder = ' style="margin-right:0;"';
								else $styleBorder = '';
								
								//Tinh thoi gian
								$starttime=time();
								$endtime=strtotime($lsNewsOthersUser[$i]->end_date);
								 
								$timediff = $endtime-$starttime;
								   $days=intval($timediff/86400);
								   $remain=$timediff%86400;
								   $hours=intval($remain/3600);
								   $remain=$remain%3600;
								   $mins=intval($remain/60);
								   $secs=$remain%60;
								//$timediff=$days.'days'.$hours.'hr'.$mins.'min'.$secs.'s';   
								?>
								<li>
									<a href="<?php echo $link;?>" class="screenshot" rel="<?php echo $path;?>/medium/<?php echo $lsNewsOthersUser[$i]->mediumImage;?>">
										<img src="<?php echo $path;?>/thumbnail/<?php echo $lsNewsOthersUser[$i]->thumbnailImage;?>" width="80" alt="" border="0" />
									</a>
									<a href="<?php echo $link;?>"><?php echo $lsNewsOthersUser[$i]->title;?></a>
									<p><?php echo mb_substr($lsNewsOthersUser[$i]->introtext, 0, 150, "utf-8")."...";?></p>
									<p class="datetime">Ngày bắt đầu: <?php echo unFormatDate($lsNewsOthersUser[$i]->start_date,"d/m/Y H:i:s");?></p>
									<p class="datetime">Ngày kết thúc: <?php echo unFormatDate($lsNewsOthersUser[$i]->end_date,"d/m/Y H:i:s");?></p>
									<div>
										<span>Thời gian còn lại: </span>
										<span class="clearfix"></span>
										<span class="timer"><?php echo $timediff=$days.' ngày, '.$hours.' giờ, '.$mins.' phút';?></span>
										<span class="clearfix"></span>
									</div>
								</li>
								<?php }?>
							</ul>
				        </div>
				        <div class="content" id="content_3" style="display: block;">
				        	<ul>
				            	<?php
								for ($i=0; $i<count($lsNewsOthersUserBlock); $i++){
								$link = sefRelToAbs("index.php?option=com_news&task=view&id=".$lsNewsOthersUserBlock[$i]->id).$lsNewsOthersUserBlock[$i]->title_alias;	
								if (($i+1%2) == 0)	$styleBorder = ' style="margin-right:0;"';
								else $styleBorder = '';
								?>
								<li>
									<a href="<?php echo $link;?>" class="screenshot" rel="<?php echo $path;?>/medium/<?php echo $lsNewsOthersUserBlock[$i]->mediumImage;?>">
										<img src="<?php echo $path;?>/thumbnail/<?php echo $lsNewsOthersUserBlock[$i]->thumbnailImage;?>" width="80" alt="" border="0" />
									</a>
									<a href="<?php echo $link;?>"><?php echo $lsNewsOthersUserBlock[$i]->title;?></a>
									<p><?php echo mb_substr($lsNewsOthersUserBlock[$i]->introtext, 0, 150, "utf-8")."...";?></p>
									<p class="datetime">Ngày bắt đầu: <?php echo unFormatDate($lsNewsOthersUserBlock[$i]->start_date,"d/m/Y H:i:s");?></p>
									<p class="datetime" style="color:red; text-decoration: line-through;">Ngày kết thúc: <?php echo unFormatDate($lsNewsOthersUserBlock[$i]->end_date,"d/m/Y H:i:s");?></p>
								</li>
								<?php }?>
							</ul>
				        </div>
				    </div>
				</div>
			</div>
		</div>
		<script>
		  // When the document loads do everything inside here ...
		  $(document).ready(function(){
			// When a link is clicked
			$("a.tab").click(function () {
				// switch all tabs off
				$(".active").removeClass("active");
				// switch this tab on
				$(this).addClass("active");
				// slide all content up
				$(".content").slideUp();
				// slide this content up
				var content_show = $(this).attr("title");
				$("#"+content_show).slideDown();
			});
		  });
	  </script>
	<?php	
	}
}
?>